<template>
  <div class="order" ref="order_echarts" style="width: 100%;height: 400px;overflow: hidden;">

  </div>
</template>

<script>
import {getOrderEcharts} from "../utils/api";

const echarts = require('echarts');
export default {
  name: "OrderEcharts",
  methods: {
    initCharts () {
      let myChart = echarts.init(this.$refs.order_echarts, null);
      // 绘制图表
      window.onresize = function () {
        myChart.resize();
      };
      myChart.setOption( {
        title: {
          text: '订单到期管理',
          left: '5%',
          top:'4%'
        },
        grid: {
          left: '-25',
          bottom: '3%',
          right:40,
          top:'50',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0,0],
          splitLine :{
            show:false
          },
          name:'（人）',
          nameGap: 40,
          nameTextStyle:{
            align:'right',
            verticalAlign:'top',
            fontSize:12,
          },
          axisLabel: {
            color: 'rgba(0,0,0,0.4)',
            fontSize:12,
          },
        },
        yAxis: [
          {
            type: 'category',
            data: ['60天内', '30天内', '15天内','7天内'],
            axisTick: {
              show: false,
            },
            position:'left',
            show:false
          },
          {
            type: 'category',
            data: ['60天内', '30天内', '15天内','7天内'],
            axisTick: {
              show: false,
            },
            position:'left',
            offset:15,
            axisLabel: {//y轴文字的配置
              textStyle: {
                color: "rgba(0,0,0,0.47)",
                fontSize:12
              },
            }
          }
        ],
        series: [
          {
            name: '2011',
            type: 'bar',
            data: this.num,
            barWidth : '40%', //柱图宽度
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
                  { offset: 0, color: '#0EECE4' },
                  { offset: 1, color: '#058FE7' }
                ]),
                label: {
                  show: true,
                  position: 'right',
                  textStyle: {
                    fontSize: 12,
                    color:"rgb(0,0,0)"
                  }
                }
              },
            },
          }
        ]
      })
      myChart.on('click', (params)=>{
        this.$router.push({path:'user/userorderall',query:{time:params.name.slice(0,-2)}})
      });
    }
  },
  mounted() {
    getOrderEcharts().then(res=>{
      if(res.status==200){
        this.num = res.body
        this.initCharts()
      }
    }).catch(err=>{
      console.log(err)
    })
  },
  data(){
    return {
      num:[0,0,0,0]
    }
  }
}
</script>

<style scoped>

</style>